﻿
namespace ATA.Windows.Forms
{
	/// <summary>
	/// abstract ChietKhauDbdsChuongTrinh typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class ChietKhauDbdsChuongTrinhDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<ChietKhauDbdsChuongTrinhDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.ChietKhauDbdsChuongTrinh _currentChietKhauDbdsChuongTrinh = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxChietKhauDbdsChuongTrinhDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxChietKhauDbdsChuongTrinhErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxChietKhauDbdsChuongTrinhBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the ChietKhauDbdsChuongTrinhId property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxChietKhauDbdsChuongTrinhIdDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the ChietKhauDacBietDsid property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxChietKhauDacBietDsidDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the ChuongTrinhId property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxChuongTrinhIdDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
				
		private Entities.TList<Entities.ChietKhauDacBietDs> _ChietKhauDacBietDsidList;
		
		/// <summary> 
		/// The list of selectable ChietKhauDacBietDs
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.ChietKhauDacBietDs> ChietKhauDacBietDsidList
		{
			get {return this._ChietKhauDacBietDsidList;}
			set 
			{
				this._ChietKhauDacBietDsidList = value;
				this.uxChietKhauDacBietDsidDataGridViewColumn.DataSource = null;
				this.uxChietKhauDacBietDsidDataGridViewColumn.DataSource = this._ChietKhauDacBietDsidList;
			}
		}
		
		private bool _allowNewItemInChietKhauDacBietDsidList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of ChietKhauDacBietDs
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInChietKhauDacBietDsidList
		{
			get { return _allowNewItemInChietKhauDacBietDsidList;}
			set
			{
				this._allowNewItemInChietKhauDacBietDsidList = value;
				this.uxChietKhauDacBietDsidDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
				
		private Entities.TList<Entities.ChuongTrinh> _ChuongTrinhIdList;
		
		/// <summary> 
		/// The list of selectable ChuongTrinh
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.ChuongTrinh> ChuongTrinhIdList
		{
			get {return this._ChuongTrinhIdList;}
			set 
			{
				this._ChuongTrinhIdList = value;
				this.uxChuongTrinhIdDataGridViewColumn.DataSource = null;
				this.uxChuongTrinhIdDataGridViewColumn.DataSource = this._ChuongTrinhIdList;
			}
		}
		
		private bool _allowNewItemInChuongTrinhIdList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of ChuongTrinh
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInChuongTrinhIdList
		{
			get { return _allowNewItemInChuongTrinhIdList;}
			set
			{
				this._allowNewItemInChuongTrinhIdList = value;
				this.uxChuongTrinhIdDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.ChietKhauDbdsChuongTrinh> _ChietKhauDbdsChuongTrinhList;
				
		/// <summary> 
		/// The list of ChietKhauDbdsChuongTrinh to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.ChietKhauDbdsChuongTrinh> ChietKhauDbdsChuongTrinhList
		{
			get {return this._ChietKhauDbdsChuongTrinhList;}
			set
			{
				this._ChietKhauDbdsChuongTrinhList = value;
				this.uxChietKhauDbdsChuongTrinhBindingSource.DataSource = null;
				this.uxChietKhauDbdsChuongTrinhBindingSource.DataSource = value;
				this.uxChietKhauDbdsChuongTrinhDataGridView.DataSource = null;
				this.uxChietKhauDbdsChuongTrinhDataGridView.DataSource = this.uxChietKhauDbdsChuongTrinhBindingSource;				
				//this.uxChietKhauDbdsChuongTrinhBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxChietKhauDbdsChuongTrinhBindingSource_ListChanged);
				this.uxChietKhauDbdsChuongTrinhBindingSource.CurrentItemChanged += new System.EventHandler(OnChietKhauDbdsChuongTrinhBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnChietKhauDbdsChuongTrinhBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentChietKhauDbdsChuongTrinh = uxChietKhauDbdsChuongTrinhBindingSource.Current as Entities.ChietKhauDbdsChuongTrinh;
			
			if (_currentChietKhauDbdsChuongTrinh != null)
			{
				_currentChietKhauDbdsChuongTrinh.Validate();
			}
			//_ChietKhauDbdsChuongTrinh.Validate();
			OnCurrentEntityChanged();
		}

		//void uxChietKhauDbdsChuongTrinhBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <see cref="Entities.ChietKhauDbdsChuongTrinh"/> instance.
		/// </summary>
		public Entities.ChietKhauDbdsChuongTrinh SelectedChietKhauDbdsChuongTrinh
		{
			get {return this._currentChietKhauDbdsChuongTrinh;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxChietKhauDbdsChuongTrinhDataGridView.VirtualMode;}
			set
			{
				this.uxChietKhauDbdsChuongTrinhDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxChietKhauDbdsChuongTrinhDataGridView.AllowUserToAddRows;}
			set {this.uxChietKhauDbdsChuongTrinhDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxChietKhauDbdsChuongTrinhDataGridView.AllowUserToDeleteRows;}
			set {this.uxChietKhauDbdsChuongTrinhDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <see cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxChietKhauDbdsChuongTrinhDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxChietKhauDbdsChuongTrinhDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="ChietKhauDbdsChuongTrinhDataGridViewBase"/> class.
		/// </summary>
		public ChietKhauDbdsChuongTrinhDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxChietKhauDbdsChuongTrinhDataGridView = new System.Windows.Forms.DataGridView();
			this.uxChietKhauDbdsChuongTrinhBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxChietKhauDbdsChuongTrinhErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxChietKhauDbdsChuongTrinhIdDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxChietKhauDacBietDsidDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxChuongTrinhIdDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			//this.uxChietKhauDacBietDsidBindingSource = new ChietKhauDacBietDsBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxChietKhauDacBietDsidBindingSource)).BeginInit();
			//this.uxChuongTrinhIdBindingSource = new ChuongTrinhBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxChuongTrinhIdBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxChietKhauDbdsChuongTrinhDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxChietKhauDbdsChuongTrinhBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxChietKhauDbdsChuongTrinhErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxChietKhauDbdsChuongTrinhErrorProvider
			// 
			this.uxChietKhauDbdsChuongTrinhErrorProvider.ContainerControl = this;
			this.uxChietKhauDbdsChuongTrinhErrorProvider.DataSource = this.uxChietKhauDbdsChuongTrinhBindingSource;						
			// 
			// uxChietKhauDbdsChuongTrinhDataGridView
			// 
			this.uxChietKhauDbdsChuongTrinhDataGridView.AutoGenerateColumns = false;
			this.uxChietKhauDbdsChuongTrinhDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxChietKhauDbdsChuongTrinhDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxChietKhauDbdsChuongTrinhIdDataGridViewColumn,
		this.uxChietKhauDacBietDsidDataGridViewColumn,
		this.uxChuongTrinhIdDataGridViewColumn			});
			this.uxChietKhauDbdsChuongTrinhDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxChietKhauDbdsChuongTrinhDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxChietKhauDbdsChuongTrinhDataGridView.Name = "uxChietKhauDbdsChuongTrinhDataGridView";
			this.uxChietKhauDbdsChuongTrinhDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxChietKhauDbdsChuongTrinhDataGridView.TabIndex = 0;	
			this.uxChietKhauDbdsChuongTrinhDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxChietKhauDbdsChuongTrinhDataGridView.EnableHeadersVisualStyles = false;
			this.uxChietKhauDbdsChuongTrinhDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnChietKhauDbdsChuongTrinhDataGridViewDataError);
			this.uxChietKhauDbdsChuongTrinhDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnChietKhauDbdsChuongTrinhDataGridViewCellValueNeeded);
			this.uxChietKhauDbdsChuongTrinhDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnChietKhauDbdsChuongTrinhDataGridViewCellValuePushed);
			
			//
			// uxChietKhauDbdsChuongTrinhIdDataGridViewColumn
			//
			this.uxChietKhauDbdsChuongTrinhIdDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxChietKhauDbdsChuongTrinhIdDataGridViewColumn.DataPropertyName = "ChietKhauDbdsChuongTrinhId";
			this.uxChietKhauDbdsChuongTrinhIdDataGridViewColumn.HeaderText = "ChietKhauDbdsChuongTrinhId";
			this.uxChietKhauDbdsChuongTrinhIdDataGridViewColumn.Name = "uxChietKhauDbdsChuongTrinhIdDataGridViewColumn";
			this.uxChietKhauDbdsChuongTrinhIdDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxChietKhauDbdsChuongTrinhIdDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxChietKhauDbdsChuongTrinhIdDataGridViewColumn.ReadOnly = true;		
			//
			// uxChietKhauDacBietDsidDataGridViewColumn
			//
			this.uxChietKhauDacBietDsidDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxChietKhauDacBietDsidDataGridViewColumn.DataPropertyName = "ChietKhauDacBietDsid";
			this.uxChietKhauDacBietDsidDataGridViewColumn.HeaderText = "ChietKhauDacBietDsid";
			this.uxChietKhauDacBietDsidDataGridViewColumn.Name = "uxChietKhauDacBietDsidDataGridViewColumn";
			this.uxChietKhauDacBietDsidDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxChietKhauDacBietDsidDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxChietKhauDacBietDsidDataGridViewColumn.ReadOnly = false;		
			//
			// uxChuongTrinhIdDataGridViewColumn
			//
			this.uxChuongTrinhIdDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxChuongTrinhIdDataGridViewColumn.DataPropertyName = "ChuongTrinhId";
			this.uxChuongTrinhIdDataGridViewColumn.HeaderText = "ChuongTrinhId";
			this.uxChuongTrinhIdDataGridViewColumn.Name = "uxChuongTrinhIdDataGridViewColumn";
			this.uxChuongTrinhIdDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxChuongTrinhIdDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxChuongTrinhIdDataGridViewColumn.ReadOnly = false;		
			//
			// uxChietKhauDacBietDsidDataGridViewColumn
			//				
			this.uxChietKhauDacBietDsidDataGridViewColumn.DisplayMember = "NhomSanPhamId";	
			this.uxChietKhauDacBietDsidDataGridViewColumn.ValueMember = "ChietKhauDacBietDsid";	
			this.uxChietKhauDacBietDsidDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxChietKhauDacBietDsidDataGridViewColumn.DataSource = uxChietKhauDacBietDsidBindingSource;				
				
			//
			// uxChuongTrinhIdDataGridViewColumn
			//				
			this.uxChuongTrinhIdDataGridViewColumn.DisplayMember = "TenChuongTrinh";	
			this.uxChuongTrinhIdDataGridViewColumn.ValueMember = "ChuongTrinhId";	
			this.uxChuongTrinhIdDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxChuongTrinhIdDataGridViewColumn.DataSource = uxChuongTrinhIdBindingSource;				
				
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxChietKhauDbdsChuongTrinhDataGridView);
			this.Name = "ChietKhauDbdsChuongTrinhDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			//((System.ComponentModel.ISupportInitialize)(this.uxChietKhauDacBietDsidBindingSource)).EndInit();
			//((System.ComponentModel.ISupportInitialize)(this.uxChuongTrinhIdBindingSource)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxChietKhauDbdsChuongTrinhErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxChietKhauDbdsChuongTrinhDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxChietKhauDbdsChuongTrinhBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				ChietKhauDbdsChuongTrinhDataGridViewEventArgs args = new ChietKhauDbdsChuongTrinhDataGridViewEventArgs();
				args.ChietKhauDbdsChuongTrinh = _currentChietKhauDbdsChuongTrinh;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class ChietKhauDbdsChuongTrinhDataGridViewEventArgs : System.EventArgs
		{
			private Entities.ChietKhauDbdsChuongTrinh	_ChietKhauDbdsChuongTrinh;
	
			/// <summary>
			/// the  Entities.ChietKhauDbdsChuongTrinh instance.
			/// </summary>
			public Entities.ChietKhauDbdsChuongTrinh ChietKhauDbdsChuongTrinh
			{
				get { return _ChietKhauDbdsChuongTrinh; }
				set { _ChietKhauDbdsChuongTrinh = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxChietKhauDbdsChuongTrinhDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnChietKhauDbdsChuongTrinhDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxChietKhauDbdsChuongTrinhDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnChietKhauDbdsChuongTrinhDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxChietKhauDbdsChuongTrinhDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxChietKhauDbdsChuongTrinhIdDataGridViewColumn":
						e.Value = ChietKhauDbdsChuongTrinhList[e.RowIndex].ChietKhauDbdsChuongTrinhId;
						break;
					case "uxChietKhauDacBietDsidDataGridViewColumn":
						e.Value = ChietKhauDbdsChuongTrinhList[e.RowIndex].ChietKhauDacBietDsid;
						break;
					case "uxChuongTrinhIdDataGridViewColumn":
						e.Value = ChietKhauDbdsChuongTrinhList[e.RowIndex].ChuongTrinhId;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxChietKhauDbdsChuongTrinhDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnChietKhauDbdsChuongTrinhDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxChietKhauDbdsChuongTrinhDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxChietKhauDbdsChuongTrinhIdDataGridViewColumn":
						ChietKhauDbdsChuongTrinhList[e.RowIndex].ChietKhauDbdsChuongTrinhId = (System.Int32)e.Value;
						break;
					case "uxChietKhauDacBietDsidDataGridViewColumn":
						ChietKhauDbdsChuongTrinhList[e.RowIndex].ChietKhauDacBietDsid = (System.Int32)e.Value;
						break;
					case "uxChuongTrinhIdDataGridViewColumn":
						ChietKhauDbdsChuongTrinhList[e.RowIndex].ChuongTrinhId = (System.Int32)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
